<<<<<<< HEAD
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultResponse;
import com.wyz.common.ResultVo;
import com.wyz.entity.CourseEntity;
import com.wyz.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2024/12/25 10:41
 */
@RestController
@Slf4j
@RequestMapping("/course")
public class CourseController {
    @Resource
    private CourseService courseService;
    //分页查询课程信息
    @AutoLog("进入课程管理页面")
    @GetMapping("/queryCourseByPage/{page}")
    public ResultVo<Map<String, Object>> queryCourseByPage(@PathVariable("page") int page) {
        log.info("分页查询课程信息请求,参数:{}", page);
        IPage<CourseEntity> courseListPage = courseService.getCourseListByPage(page);
        List<CourseEntity> courseList = courseListPage.getRecords();//获取分页查询结果
        int total = (int)courseListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("courseList",courseList);
        resultMap.put("pageList",pageList);

        log.info("获取分页课程列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }
    //添加课程信息
    @AutoLog("添加课程信息")
    @PostMapping("/addCourse")
    public ResultVo<Boolean> addCourse(@RequestBody CourseEntity courseEntity) {
        log.info("添加课程信息请求,参数:{}", courseEntity);
        try {
            if (courseService.addCourse(courseEntity)){
                log.info("添加课程信息成功:{}",courseEntity);
                return new ResultVo<>(200,"ok",true);
            }
            return ResultVo.fail();
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //根据id查询课程信息
    @AutoLog("根据id查询课程信息")
    @GetMapping("/queryCourseById/{courseId}")
    public ResultVo<CourseEntity> queryCourseById(@PathVariable("courseId") Integer courseId) {
        log.info("根据id查询课程信息请求,参数:{}", courseId);
        CourseEntity courseEntity = courseService.queryCourseById(courseId);
        log.info("根据id查询课程信息响应,参数:{}", courseEntity);
        return new ResultVo<>(200,"ok",courseEntity);
    }
    //修改课程信息
    @AutoLog("修改课程信息")
    @PostMapping("/updateCourse")
    public ResultVo<Boolean> updateCourse(@RequestBody CourseEntity courseEntity) {
        log.info("修改课程信息请求,参数:{}", courseEntity);
        try {
            boolean b =courseService.updateCourse(courseEntity);
            return new ResultVo<>(200,"ok",b);
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //删除课程信息
    @AutoLog("删除课程信息")
    @GetMapping("/deleteCourse/{courseId}")
    public ResultVo<Boolean> deleteCourse(@PathVariable("courseId") Integer courseId) {
        log.info("删除课程信息请求,参数:{}", courseId);
        try{
            boolean b =courseService.deleteCourse(courseId);
            return new ResultVo<>(200,"ok",b);
        }catch (Exception e){
            return ResultVo.fail();
        }
    }


}
=======
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultResponse;
import com.wyz.common.ResultVo;
import com.wyz.entity.CourseEntity;
import com.wyz.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2024/12/25 10:41
 */
@RestController
@Slf4j
@RequestMapping("/course")
public class CourseController {
    @Resource
    private CourseService courseService;
    //分页查询课程信息
    @AutoLog("进入课程管理页面")
    @GetMapping("/queryCourseByPage/{page}")
    public ResultVo<Map<String, Object>> queryCourseByPage(@PathVariable("page") int page) {
        log.info("分页查询课程信息请求,参数:{}", page);
        IPage<CourseEntity> courseListPage = courseService.getCourseListByPage(page);
        List<CourseEntity> courseList = courseListPage.getRecords();//获取分页查询结果
        int total = (int)courseListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("courseList",courseList);
        resultMap.put("pageList",pageList);

        log.info("获取分页课程列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }
    //添加课程信息
    @AutoLog("添加课程信息")
    @PostMapping("/addCourse")
    public ResultVo<Boolean> addCourse(@RequestBody CourseEntity courseEntity) {
        log.info("添加课程信息请求,参数:{}", courseEntity);
        try {
            if (courseService.addCourse(courseEntity)){
                log.info("添加课程信息成功:{}",courseEntity);
                return new ResultVo<>(200,"ok",true);
            }
            return ResultVo.fail();
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //根据id查询课程信息
    @AutoLog("根据id查询课程信息")
    @GetMapping("/queryCourseById/{courseId}")
    public ResultVo<CourseEntity> queryCourseById(@PathVariable("courseId") Integer courseId) {
        log.info("根据id查询课程信息请求,参数:{}", courseId);
        CourseEntity courseEntity = courseService.queryCourseById(courseId);
        log.info("根据id查询课程信息响应,参数:{}", courseEntity);
        return new ResultVo<>(200,"ok",courseEntity);
    }
    //修改课程信息
    @AutoLog("修改课程信息")
    @PostMapping("/updateCourse")
    public ResultVo<Boolean> updateCourse(@RequestBody CourseEntity courseEntity) {
        log.info("修改课程信息请求,参数:{}", courseEntity);
        try {
            boolean b =courseService.updateCourse(courseEntity);
            return new ResultVo<>(200,"ok",b);
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //删除课程信息
    @AutoLog("删除课程信息")
    @GetMapping("/deleteCourse/{courseId}")
    public ResultVo<Boolean> deleteCourse(@PathVariable("courseId") Integer courseId) {
        log.info("删除课程信息请求,参数:{}", courseId);
        try{
            boolean b =courseService.deleteCourse(courseId);
            return new ResultVo<>(200,"ok",b);
        }catch (Exception e){
            return ResultVo.fail();
        }
    }


}
>>>>>>> be516e15a35375b38cf973b1ce88c92dd1ceba03
